home *** CD-ROM | disk | FTP | other *** search
/ Borland JBuilder 6 / jbuilder6.iso / Taiji Applet Pack v2.7 / ImageConvex2 / ImageConvex2.class (.txt) < prev    next >
Encoding:
Java Class File  |  2001-11-06  |  11.2 KB  |  473 lines

  1. import java.applet.Applet;
  2. import java.applet.AudioClip;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Image;
  10. import java.awt.MediaTracker;
  11. import java.awt.event.MouseEvent;
  12. import java.awt.event.MouseListener;
  13. import java.awt.event.MouseMotionListener;
  14. import java.awt.image.MemoryImageSource;
  15. import java.awt.image.PixelGrabber;
  16. import java.net.MalformedURLException;
  17. import java.net.URL;
  18. import java.net.URLEncoder;
  19.  
  20. public class ImageConvex2 extends Applet implements Runnable, MouseListener, MouseMotionListener {
  21.    boolean loaded;
  22.    Thread thread;
  23.    Image image;
  24.    Image buffer;
  25.    // $FF: renamed from: b java.awt.Graphics
  26.    Graphics field_0;
  27.    Color backColor;
  28.    // $FF: renamed from: wi int
  29.    int field_1;
  30.    // $FF: renamed from: he int
  31.    int field_2;
  32.    int wiIm;
  33.    int heIm;
  34.    int pause = 20;
  35.    static int[] pix;
  36.    static int[] pixnew;
  37.    int radius;
  38.    // $FF: renamed from: X int
  39.    int field_3;
  40.    // $FF: renamed from: Y int
  41.    int field_4;
  42.    float IConv = 1.0F;
  43.    float IConvIni;
  44.    int dimMin;
  45.    private String statusBarText;
  46.    private AudioClip sound;
  47.    private AudioClip clicSound;
  48.    private AudioClip enterSound;
  49.    private boolean loopSound;
  50.    private String link;
  51.    // $FF: renamed from: fm java.awt.FontMetrics
  52.    private FontMetrics field_5;
  53.    private String enterText;
  54.    private boolean isEnterTextEnabled;
  55.    private int wiEnterText;
  56.    private int enterTextHeight;
  57.    private Color enterTextColor;
  58.    private int decx;
  59.    private int decy;
  60.  
  61.    public String getAppletInfo() {
  62.       return "Name: ImageConvex2\r\nAuthor: Taiji Software\r\n";
  63.    }
  64.  
  65.    public ImageConvex2() {
  66.       this.backColor = Color.black;
  67.       this.IConvIni = 4.0F;
  68.       this.radius = 30;
  69.       ((Component)this).addMouseListener(this);
  70.       ((Component)this).addMouseMotionListener(this);
  71.    }
  72.  
  73.    public void register() {
  74.       try {
  75.          URL u = new URL("http://www.taijisoftware.com");
  76.          ((Applet)this).getAppletContext().showDocument(u, "_blank");
  77.          this.stop();
  78.       } catch (Exception e) {
  79.          System.out.println(e);
  80.          this.stop();
  81.       }
  82.    }
  83.  
  84.    public void init() {
  85.       String codeBase = null;
  86.  
  87.       try {
  88.          codeBase = (new URL(((Applet)this).getCodeBase().toString())).getHost();
  89.          System.out.println("Copyright 1999, 2001 Taiji Software(tm)\nYour domain name is : " + codeBase);
  90.          codeBase = codeBase.toUpperCase();
  91.       } catch (Exception var11) {
  92.       }
  93.  
  94.       if (!((Applet)this).getCodeBase().toString().toUpperCase().startsWith("FILE") || ((Applet)this).getParameter("debug") != null) {
  95.          String regCode = ((Applet)this).getParameter("registration_code");
  96.          if (regCode == null) {
  97.             regCode = ((Applet)this).getParameter("reg_domain");
  98.             if (regCode == null) {
  99.                this.register();
  100.             } else {
  101.                if (regCode.length() == codeBase.length() + 4 && !codeBase.startsWith("WWW.")) {
  102.                   codeBase = "WWW." + codeBase;
  103.                } else if (regCode.length() == codeBase.length() - 4 && codeBase.startsWith("WWW.")) {
  104.                   codeBase = codeBase.substring(4);
  105.                }
  106.  
  107.                char[] chars = new char[codeBase.length()];
  108.                codeBase.getChars(0, codeBase.length(), chars, 0);
  109.                String key = new String("haricot");
  110.                char[] chars2 = new char[key.length()];
  111.                key.getChars(0, key.length(), chars2, 0);
  112.  
  113.                for(int i = 0; i < codeBase.length(); ++i) {
  114.                   int j;
  115.                   if (i >= key.length()) {
  116.                      j = i - key.length() * (i / key.length());
  117.                   } else {
  118.                      j = i;
  119.                   }
  120.  
  121.                   chars[i] += chars2[j];
  122.                   chars[i] = (char)(chars[i] - chars[i] / 26 * 26 + 97);
  123.                }
  124.  
  125.                String res = new String(chars);
  126.                if (!res.equalsIgnoreCase(regCode)) {
  127.                   this.register();
  128.                }
  129.             }
  130.          } else if (!regCode.equals("settevercsedegnamiaj") && !regCode.equals("8078")) {
  131.             this.register();
  132.          }
  133.       }
  134.  
  135.       this.getParameters();
  136.       this.image = ((Applet)this).getImage(((Applet)this).getCodeBase(), ((Applet)this).getParameter("image_name"));
  137.       MediaTracker tracker = new MediaTracker(this);
  138.       tracker.addImage(this.image, 0);
  139.  
  140.       try {
  141.          tracker.waitForAll();
  142.          tracker.isErrorAny();
  143.       } catch (Exception e) {
  144.          System.err.println(e);
  145.       }
  146.  
  147.       if (!this.loaded) {
  148.          this.stop();
  149.       }
  150.  
  151.       this.wiIm = this.image.getWidth(this);
  152.       this.heIm = this.image.getHeight(this);
  153.       this.decx = (this.field_1 - this.wiIm) / 2;
  154.       this.decy = (this.field_2 - this.heIm) / 2;
  155.       pix = new int[this.wiIm * this.heIm];
  156.       pixnew = new int[this.wiIm * this.heIm];
  157.       PixelGrabber pixg = new PixelGrabber(this.image, 0, 0, this.wiIm, this.heIm, pix, 0, this.wiIm);
  158.  
  159.       try {
  160.          pixg.grabPixels();
  161.       } catch (InterruptedException var9) {
  162.       }
  163.  
  164.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  165.       this.buffer = ((Component)this).createImage(this.field_1, this.field_2);
  166.       this.field_0 = this.buffer.getGraphics();
  167.       this.field_0.setColor(this.enterTextColor);
  168.       String fontName = ((Applet)this).getParameter("enter_text_font");
  169.       if (fontName == null) {
  170.          fontName = "TimesRoman";
  171.       }
  172.  
  173.       int style = 1;
  174.       String s = ((Applet)this).getParameter("enter_text_style");
  175.       if (s != null) {
  176.          if (s.equals("bold")) {
  177.             style = 1;
  178.          } else if (s.equals("italic")) {
  179.             style = 2;
  180.          } else if (s.equals("bold_italic")) {
  181.             style = 3;
  182.          } else {
  183.             style = 0;
  184.          }
  185.       }
  186.  
  187.       this.field_0.setFont(new Font(fontName, style, this.enterTextHeight));
  188.       this.field_5 = this.field_0.getFontMetrics();
  189.       if (this.enterText != null) {
  190.          this.wiEnterText = this.field_5.stringWidth(this.enterText);
  191.       }
  192.  
  193.       this.field_3 = (int)((float)this.wiIm / 2.0F);
  194.       this.field_4 = (int)((float)this.heIm / 2.0F);
  195.       if (this.wiIm >= this.heIm) {
  196.          this.dimMin = this.heIm;
  197.       } else {
  198.          this.dimMin = this.wiIm;
  199.       }
  200.  
  201.       if (this.sound != null) {
  202.          if (this.loopSound) {
  203.             this.sound.loop();
  204.             return;
  205.          }
  206.  
  207.          this.sound.play();
  208.       }
  209.  
  210.    }
  211.  
  212.    public void getParameters() {
  213.       this.field_1 = ((Component)this).getSize().width;
  214.       this.field_2 = ((Component)this).getSize().height;
  215.       String s = ((Applet)this).getParameter("pause");
  216.       if (s != null) {
  217.          this.pause = Integer.parseInt(s);
  218.       }
  219.  
  220.       this.backColor = this.getColor("background_color");
  221.       ((Component)this).setBackground(this.backColor);
  222.       s = ((Applet)this).getParameter("radius");
  223.       if (s != null) {
  224.          this.radius = Integer.parseInt(s);
  225.       }
  226.  
  227.       s = ((Applet)this).getParameter("convexity");
  228.       if (s != null) {
  229.          this.IConvIni = (float)((double)((float)Integer.parseInt(s)) / (double)10.0F);
  230.       }
  231.  
  232.       this.statusBarText = ((Applet)this).getParameter("status_bar_text");
  233.       s = ((Applet)this).getParameter("sound_name");
  234.       if (s != null) {
  235.          this.sound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  236.       }
  237.  
  238.       s = ((Applet)this).getParameter("loop_sound");
  239.       if (s != null) {
  240.          if (s.equals("yes")) {
  241.             this.loopSound = true;
  242.          } else {
  243.             this.loopSound = false;
  244.          }
  245.       }
  246.  
  247.       s = ((Applet)this).getParameter("clic_sound_name");
  248.       if (s != null) {
  249.          this.clicSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  250.       }
  251.  
  252.       s = ((Applet)this).getParameter("enter_sound_name");
  253.       if (s != null) {
  254.          this.enterSound = ((Applet)this).getAudioClip(((Applet)this).getCodeBase(), s);
  255.       }
  256.  
  257.       this.link = ((Applet)this).getParameter("link");
  258.       this.enterText = ((Applet)this).getParameter("enter_text");
  259.       s = ((Applet)this).getParameter("enter_text_height");
  260.       if (s != null) {
  261.          this.enterTextHeight = Integer.parseInt(s);
  262.       }
  263.  
  264.       this.enterTextColor = this.getColor("enter_text_color");
  265.       if (this.enterTextColor == null) {
  266.          this.enterTextColor = Color.white;
  267.       }
  268.  
  269.    }
  270.  
  271.    public Color getColor(String param) {
  272.       String s = ((Applet)this).getParameter(param);
  273.       if (s != null) {
  274.          if (s.substring(0, 1).equals("#")) {
  275.             s = s.substring(1);
  276.             int i = Integer.parseInt(s, 16);
  277.             return new Color(i);
  278.          } else {
  279.             return null;
  280.          }
  281.       } else {
  282.          return null;
  283.       }
  284.    }
  285.  
  286.    public void start() {
  287.       if (this.thread == null) {
  288.          this.thread = new Thread(this);
  289.          this.thread.start();
  290.       }
  291.  
  292.    }
  293.  
  294.    public void stop() {
  295.       if (this.thread != null) {
  296.          this.thread = null;
  297.       }
  298.  
  299.       if (this.sound != null) {
  300.          this.sound.stop();
  301.       }
  302.  
  303.    }
  304.  
  305.    public void run() {
  306.       Thread.currentThread().setPriority(4);
  307.  
  308.       while(true) {
  309.          ((Component)this).repaint();
  310.  
  311.          try {
  312.             Thread.sleep((long)this.pause);
  313.          } catch (InterruptedException var1) {
  314.          }
  315.  
  316.          this.calculatePixels();
  317.       }
  318.    }
  319.  
  320.    public final void paint(Graphics g) {
  321.       if (!this.loaded) {
  322.          this.field_0.setColor(Color.white);
  323.          this.field_0.drawString("loading... please wait", 1, this.field_2 / 2);
  324.          this.loaded = true;
  325.       } else {
  326.          if (this.image != null) {
  327.             this.field_0.clearRect(0, 0, this.field_1, this.field_2);
  328.             this.field_0.drawImage(this.image, this.decx, this.decy, this);
  329.             if (this.isEnterTextEnabled) {
  330.                this.field_0.drawString(this.enterText, (this.field_1 - this.wiEnterText) / 2, this.field_2 / 2);
  331.             }
  332.  
  333.             this.image = null;
  334.          }
  335.  
  336.          g.drawImage(this.buffer, 0, 0, this);
  337.       }
  338.    }
  339.  
  340.    public final void update(Graphics g) {
  341.       this.paint(g);
  342.    }
  343.  
  344.    private final void calculatePixels() {
  345.       for(int ii = 0; ii < this.heIm; ++ii) {
  346.          for(int jj = 0; jj < this.wiIm; ++jj) {
  347.             int i = jj - this.field_3 + this.decx;
  348.             int j = ii - this.field_4 + this.decy;
  349.             float r1 = (float)Math.sqrt((double)(i * i + j * j));
  350.             float r2 = 1.0F;
  351.             if (r1 < (float)this.radius) {
  352.                r2 = this.IConv - (this.IConv - 1.0F) * r1 / (float)this.radius;
  353.             }
  354.  
  355.             float r3 = (float)i / r2 + (float)(this.field_3 - this.decx);
  356.             float r4 = (float)j / r2 + (float)(this.field_4 - this.decy);
  357.             if (r1 < (float)this.radius) {
  358.                if (r3 > 0.0F && r3 < (float)(this.wiIm - 1) && r4 > 0.0F && r4 < (float)(this.heIm - 1)) {
  359.                   float r5 = r3 - (float)((int)r3);
  360.                   float r6 = r4 - (float)((int)r4);
  361.                   int a = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 16711680, 16) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 16711680, 16) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 16711680, 16) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 16711680, 16));
  362.                   int b = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 65280, 8) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 65280, 8) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 65280, 8) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 65280, 8));
  363.                   int c = (int)((1.0F - r5) * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3, 255, 0) + (1.0F - r5) * r6 * (float)this.pixel((int)r4 + 1, (int)r3, 255, 0) + r5 * (1.0F - r6) * (float)this.pixel((int)r4, (int)r3 + 1, 255, 0) + r5 * r6 * (float)this.pixel((int)r4 + 1, (int)r3 + 1, 255, 0));
  364.                   pixnew[ii * this.wiIm + jj] = (new Color(a, b, c)).getRGB();
  365.                } else {
  366.                   pixnew[ii * this.wiIm + jj] = this.backColor.getRGB();
  367.                }
  368.             } else {
  369.                pixnew[ii * this.wiIm + jj] = pix[ii * this.wiIm + jj];
  370.             }
  371.          }
  372.       }
  373.  
  374.       this.image = ((Component)this).createImage(new MemoryImageSource(this.wiIm, this.heIm, pixnew, 0, this.wiIm));
  375.    }
  376.  
  377.    public final int pixel(int i, int j, int hex, int dec) {
  378.       return (pix[i * this.wiIm + j] & hex) >> dec;
  379.    }
  380.  
  381.    public URL giveURL(String url) {
  382.       try {
  383.          if (url.toUpperCase().startsWith("HTTP")) {
  384.             return new URL(url);
  385.          } else if (url.toUpperCase().startsWith("FTP")) {
  386.             int p = url.indexOf(":");
  387.             int p2 = url.indexOf(":", p + 1);
  388.             if (p2 != -1) {
  389.                url = url.substring(0, p + 3) + URLEncoder.encode(url.substring(p + 3, url.length()));
  390.             }
  391.  
  392.             p = url.indexOf("%40");
  393.             if (p != -1) {
  394.                url = url.substring(0, p) + "@" + url.substring(p + 3, url.length());
  395.             }
  396.  
  397.             return new URL(url);
  398.          } else {
  399.             return new URL(((Applet)this).getCodeBase(), url);
  400.          }
  401.       } catch (MalformedURLException e) {
  402.          System.out.println(e);
  403.          return null;
  404.       }
  405.    }
  406.  
  407.    public void mouseClicked(MouseEvent e) {
  408.    }
  409.  
  410.    public void mouseEntered(MouseEvent e) {
  411.       this.IConv = this.IConvIni;
  412.       if (this.enterText != null) {
  413.          this.isEnterTextEnabled = true;
  414.          this.field_0.setColor(this.enterTextColor);
  415.          ((Component)this).repaint();
  416.       }
  417.  
  418.       if (this.statusBarText != null) {
  419.          ((Applet)this).showStatus(this.statusBarText);
  420.       }
  421.  
  422.       if (this.enterSound != null) {
  423.          this.enterSound.play();
  424.       }
  425.  
  426.       if (this.link != null) {
  427.          ((Component)this).setCursor(new Cursor(12));
  428.       }
  429.  
  430.    }
  431.  
  432.    public void mouseExited(MouseEvent e) {
  433.       this.IConv = 1.0F;
  434.       if (this.isEnterTextEnabled) {
  435.          this.isEnterTextEnabled = false;
  436.          ((Component)this).repaint();
  437.       }
  438.  
  439.       if (this.link != null) {
  440.          ((Component)this).setCursor(new Cursor(0));
  441.       }
  442.  
  443.    }
  444.  
  445.    public void mousePressed(MouseEvent e) {
  446.       if (this.clicSound != null) {
  447.          this.clicSound.play();
  448.       }
  449.  
  450.       if (this.link != null) {
  451.          String target = ((Applet)this).getParameter("target");
  452.          if (target == null) {
  453.             target = "_blank";
  454.          }
  455.  
  456.          URL u = this.giveURL(this.link);
  457.          ((Applet)this).getAppletContext().showDocument(u, target);
  458.       }
  459.  
  460.    }
  461.  
  462.    public void mouseReleased(MouseEvent e) {
  463.    }
  464.  
  465.    public void mouseDragged(MouseEvent e) {
  466.    }
  467.  
  468.    public void mouseMoved(MouseEvent e) {
  469.       this.field_3 = e.getX();
  470.       this.field_4 = e.getY();
  471.    }
  472. }
  473.